<template>
  <el-dialog title="添加请假审批" :visible.sync="dialogFormVisible">
    <el-form :model="form" name="el-form-goods-category-edit-name" id="el-form-goods-category-edit-id">
      <el-form-item label="请假标题" :label-width="formLabelWidth">
        <el-input v-model="form.name" name="name" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="请假事由" :label-width="formLabelWidth">
        <el-input v-model="form.detail"  name="detail" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="请假开始时间" style="width: 100%">
        <el-date-picker
          v-model="form.startDate"
          type="datetime"
          placeholder="选择请假开始时间"
          default-time="8:00:00">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="请假结束时间"  style="width: 100%">
        <el-date-picker
          v-model="form.endDate"
          type="datetime"
          placeholder="选择请假结束时间"
          default-time="18:00:00">
        </el-date-picker>
      </el-form-item>

    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取消</el-button>
      <el-button type="primary" @click="_okDraft">暂存</el-button>
      <el-button type="primary" @click="_okSubmit">提交审批</el-button>
    </div>
  </el-dialog>
</template>

<script>

    export default {

        name: "SysUserEdit",
      data(){
          return{

            formAdd:{
              name:'',
              detail:'',
              startDate:'',
              endDate:''
            },
            form:{
              name:'',
              detail:'',
              startDate:'',
              endDate:''
            },
            dialogFormVisible: false,

            formLabelWidth: '120px'
          }
      },
      methods:{

          _open(obj){
            if (undefined===obj){

              this.form= JSON.parse(JSON.stringify(this.formAdd));;
              console.log('-----formAdd------',this.formAdd)
              this.dialogFormVisible=true;
            }else{
              this.form=obj;
              this.dialogFormVisible=true;
            }

          },


        _okDraft(){
          let userData= this.form;
          if (undefined === userData.id){
            this.$http.post('/leave/add_draft',userData).then(res=>{

              console.log('res----------------',res)

              this.$message({
                type: 'success',
                message: '添加成功!'
              });
              this.$emit('on-result-change')
              this.dialogFormVisible = false;

            }).catch(err=>{
              this.$message({
                type: 'info',
                message: '添加失败'
              });
            })

          } else {
            this.$http.put('/leave/'+userData.id,userData).then(res=>{
              this.$message({
                type: 'success',
                message: '编辑成功!'
              });
              this.$emit('on-result-change')
              this.dialogFormVisible = false;

            }).catch(err=>{
              this.$message({
                type: 'info',
                message: '编辑失败'
              });
            })
          }
        },

        _okSubmit(){
          let userData= this.form;
          if (undefined === userData.id){
            this.$http.post('/leave/add_submit',userData).then(res=>{
              this.$message({
                type: 'success',
                message: '审批提交成功!'
              });
              this.$emit('on-result-change')
              this.dialogFormVisible = false;

            }).catch(err=>{
              this.$message({
                type: 'info',
                message: '审批提交失败'
              });
            })

          } else {
            this.$http.put('/leave/'+userData.id,userData).then(res=>{
              this.$message({
                type: 'success',
                message: '编辑成功!'
              });
              this.$emit('on-result-change')
              this.dialogFormVisible = false;

            }).catch(err=>{
              this.$message({
                type: 'info',
                message: '编辑失败'
              });
            })
          }
        },

          _ok(){
            let userData= this.form;
            if (undefined === userData.id){
              this.$http.post('/t_category/add',userData).then(res=>{

                console.log('res----------------',res)

                this.$message({
                  type: 'success',
                  message: '添加成功!'
                });
                this.$emit('on-result-change')
                this.dialogFormVisible = false;

              }).catch(err=>{
                this.$message({
                  type: 'info',
                  message: '添加失败'
                });
              })

            } else {
              this.$http.put('/t_category/'+userData.id,userData).then(res=>{
                this.$message({
                  type: 'success',
                  message: '编辑成功!'
                });
                this.$emit('on-result-change')
                this.dialogFormVisible = false;

              }).catch(err=>{
                this.$message({
                  type: 'info',
                  message: '编辑失败'
                });
              })
            }
          }

      },
    }
</script>

<style scoped>

</style>
